package com.weigee.ktv.view.widget

import android.app.Activity
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.FrameLayout
import com.bumptech.glide.Glide
import com.weigee.ktv.R
import com.weigee.ktv.model.enums.WeigeeHost
import kotlinx.android.synthetic.main.wrap_title_bar.view.*

/**
 * Created by linde on 2017/5/28.
 *<p/>
 */
class MyTitleBar @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : FrameLayout(context, attrs, defStyleAttr)
{
    var title: String? = null
        set(value)
        {
            field = value
            tv_my_title?.text = value
        }
    var leftIconClickBack: Activity? = null
        set(value)
        {
            value?.let {
                iv_my_left_icon?.setOnClickListener { it@ value.onBackPressed() }
            } ?: let {
                iv_my_left_icon?.setOnClickListener(null)
            }
        }

    init
    {
        LayoutInflater.from(context).inflate(R.layout.wrap_title_bar, this, true)
        attrs?.let {
            val typeArray = context.obtainStyledAttributes(it, R.styleable.MyTitleBar)
            title = typeArray.getString(R.styleable.MyTitleBar_title_brief)
            typeArray.recycle()
        }
        Glide.with(context).load(WeigeeHost.TEST_IMAGE.url).into(iv_my_left_icon)
    }
}